<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
</head>
<script src="http://how2j.cn/study/js/jquery/2.0.0/jquery.min.js"></script>
<script src="http://how2j.cn/study/vue.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<body>
<div class="container" id="app">
    <div class="row">
        <div class="col-xs-12">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>英雄名称</th>
                    <th>血量</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="hero in heros" style="text-align: center;">
                    <td>{{hero.name}}</td>
                    <td>{{hero.hp}}</td>
                    <td>
                        <button v-on:click="del(hero.id)" class="btn btn-default">删除</button>
                        <button v-on:click="update(hero.id)" class="btn btn-default">编辑</button>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="text" v-model="hero4Add.name"/>
                    </td>
                    <td>
                        <input type="number" v-model="hero4Add.hp"/>
                    </td>
                    <td>
                        <button v-on:click="add" class="btn btn-default">添加</button>
                    </td>
                </tr>
                </tbody>
                <table>
        </div>
    </div>
</div>

</body>
<script>
    var data = {
        heros: [
            { id: 1, name: '盖伦', hp: 318},
            { id: 2, name: '提莫', hp: 320},
            { id: 3, name: '安妮', hp: 419},
            { id: 4, name: '死歌', hp: 325},
            { id: 5, name: '米波', hp: 422},
        ],
        hero4Add: { id: 0, name: '', hp: '0'},
        hero4Update: { id: 0, name: '', hp: '0'}
    };
    var vue =new Vue({
        el:'#app',
        data:data,
        methods:{
            del:function(val){
                for(var i=0;i<this.heros.length;i++){
                    if(this.heros[i].id==val){
                        this.heros.splice(i,1);
                    }

                }
                console.log(this.heros);
            },
            update:function(val){

            },
            add:function(){
                this.hero4Add.id=this.heros.length+1;
                this.heros.push(this.hero4Add);
                this.hero4Add={ id: 0, name: '', hp: '0'};
            }
        }
    })
</script>
</html>
